package com.example.foobar.dao.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.foobar.entity.ImsGhostQrcodes;
import com.example.foobar.mapper.ImsGhostQrcodesMapper;
import com.example.foobar.dao.service.ImsGhostQrcodesDaoService;
import com.example.foobar.param.ImsGhostQrcodesPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 *  服务实现类
 *
 * @author 郑英奔
 * @since 2021-07-15
 */
@Slf4j
@Service
@DS("db1")
public class ImsGhostQrcodesDaoServiceImpl extends BaseServiceImpl<ImsGhostQrcodesMapper, ImsGhostQrcodes> implements ImsGhostQrcodesDaoService {

    @Autowired
    private ImsGhostQrcodesMapper imsGhostQrcodesMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveImsGhostQrcodes(ImsGhostQrcodes imsGhostQrcodes)  {
        return super.save(imsGhostQrcodes);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateImsGhostQrcodes(ImsGhostQrcodes imsGhostQrcodes)  {
        return super.updateById(imsGhostQrcodes);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteImsGhostQrcodes(Long id)  {
        return super.removeById(id);
    }

    @Override
    public Paging<ImsGhostQrcodes> getImsGhostQrcodesPageList(ImsGhostQrcodesPageParam imsGhostQrcodesPageParam)  {
        Page<ImsGhostQrcodes> page = new PageInfo<>(imsGhostQrcodesPageParam, OrderItem.desc(getLambdaColumn(ImsGhostQrcodes::getCreateTime)));
        LambdaQueryWrapper<ImsGhostQrcodes> wrapper = new LambdaQueryWrapper<>();
        IPage<ImsGhostQrcodes> iPage = imsGhostQrcodesMapper.selectPage(page, wrapper);
        return new Paging<ImsGhostQrcodes>(iPage);
    }

    @Override
    public List<ImsGhostQrcodes> selectList(QueryWrapper<ImsGhostQrcodes> eq) {
        eq.select("id,uniacid,scene_name,scene_id,action_name,keyword,promoter,remark,ticket,reply,scan_reply,scan_keyword,url,expire_seconds,create_time,subscribe,unsubscribe,scan,openid,poster_id,fans_add_reply,fans_cancel_reply,reply_type,scan_reply_type");
        return imsGhostQrcodesMapper.selectList(eq);
    }

}
